<template>
  <page-main>
    <a-card title="密码修改">
      <a-form-model
        ref="current_form"
        :rules="rules"
        :model="current_form"
        style="width: 80vh;"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
      >
        <a-form-model-item label="现行密码" prop="password">
          <a-input-password v-model="current_form.oldPassword" placeholder="您的现行密码" />
        </a-form-model-item>
        <a-form-model-item label="新的密码" prop="newPassword">
          <a-input-password v-model="current_form.newPassword" placeholder="新的密码" />
        </a-form-model-item>

        <a-form-model-item style="margin-left: 33.3%;">
          <a-button type="primary" @click="save_userInfo">保存</a-button>
          <a-button style="margin-left: 10px;">取消</a-button>
        </a-form-model-item>
      </a-form-model>
    </a-card>
  </page-main>
</template>

<script>
import {updatePassWord} from '@/api/requests/rq-manage.js'
import * as CryptoUtils from '@/util/cryptoUtils.js';
import * as pub from '@/util/pub.js';
import {Success, Warning} from "@/util/message";

export default {
  name: 'user_reset_pwd',
  data () {
    return {
      current_form: {}
    }
  },
    methods: {
        async save_userInfo() {
            this.current_form.oldPassword = CryptoUtils.encryptByRSA(pub.pubKey(),this.current_form.oldPassword);
            this.current_form.newPassword = CryptoUtils.encryptByRSA(pub.pubKey(),this.current_form.newPassword);
            return await updatePassWord(this.current_form).then(res => {
                this.current_form.oldPassword = ''
                this.current_form.newPassword = ''
                if (res.code === 200) {
                    Success(this, '操作成功')
                } else {
                    Warning(this, '操作失败')
                }
            })

        }
    }
}
</script>
